import java.util.Scanner;
import java.util.Stack;

public class Test3 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        System.out.println(isValid(line));
    }
    public static boolean isValid(String line) {
        Stack<Character> s = new Stack<>();
        for (int i = 0; i < line.length(); i++) {
            char c = line.charAt(i);
            if (c == '(' || c == '[' || c == '{') {
                s.push(c);
            } else {
                if (s.empty()) {
                    return false;
                }
                char c2 = s.peek();
                if (c2 == '(' && c == ')' || c2 == '[' && c == ']' || c2 == '{' && c == '}') {
                    s.pop();
                } else {
                    return false;
                }
            }
        }
        if (!s.empty()) {
            return false;
        }
        return true;
    }
}
